package com.huluobo.high3videoproject.mvp.goods.view;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.huluobo.base.view.BaseFragment;
import com.huluobo.high3videoproject.R;
import com.huluobo.high3videoproject.adapter.GoodsInfoAdapter;
import com.huluobo.high3videoproject.bean.GoodsInfoBeanResult;
import com.huluobo.high3videoproject.mvp.goods.presenter.GoodsInfoContract;
import com.huluobo.high3videoproject.mvp.goods.presenter.GoodsInfoPresenter;

import java.util.ArrayList;
import java.util.List;

public class FollowFragment extends BaseFragment<GoodsInfoContract.View, GoodsInfoPresenter> implements GoodsInfoContract.View {
    private RecyclerView recyclerView;

    private GoodsInfoAdapter goodsInfoAdapter;

    private List<GoodsInfoBeanResult.GoodsInfo> goodsInfoList = new ArrayList<>();

    @Override
    public void onGetGoodsInfoSuccess(GoodsInfoBeanResult goodsInfoBeanResult) {
        goodsInfoList.addAll(goodsInfoBeanResult.getData());
        goodsInfoAdapter.notifyDataSetChanged();
    }

    @Override
    public void onGetGoodsInfoFailed(String error) {
        Log.i("TagA", "error:" + error);
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.fragment_follow;
    }

    @Override
    protected void initData() {
        presenter = new GoodsInfoPresenter();
        presenter.getGoodsInfo(0, 1, 10);
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.goodsInfo_recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
        goodsInfoAdapter = new GoodsInfoAdapter(goodsInfoList);
        recyclerView.setAdapter(goodsInfoAdapter);
    }
}